/*
+--------------------------
| FreeloaderOS v0.0.1
|  - Microkernel
+--------------------------
| Written by Alec Hussey
| Copyright (c) 2007
|  - Deus X Foundation
+---------------------------
*/

/*
 * Main / Kernel Init
 */

#include <sys/system.h>
#include <sys/colors.h>

int main(void)
{
	init_gdt();
	init_idt();
	init_isrs();
	init_irq();
	init_video();
	init_timer();
	init_keyboard();
	
	__asm__ __volatile__("sti");
	
	set_text_color(COLOR_BLACK, COLOR_RED);
	putstr("FreeloaderOS v0.0.1\n\n");
	
	init_memtest();
	return 0;
}

void outportb (unsigned short _port, unsigned char _data)
{
	__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

unsigned char inportb (unsigned short _port)
{
	unsigned char rv;
	__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
	return rv;
}

void panic(unsigned char *message, unsigned char *error_code)
{	
	clear_screen();
	set_text_color(COLOR_BLUE, COLOR_WHITE);
	clear_screen();
	putstr("Kernel Panic\n");
	putstr("\n\t");
	putstr(message);
	putstr("\t");
	putstr(error_code);
	putstr("\n\n\aYou may now restart your system.");
	
	for (;;);
}
